package day_2023_7_to_10;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author haomin
 * @date 2023/07/24 23:38
 **/
public class Day_7_24 {
    class CQueue {
        Deque<Integer> s1;
        Deque<Integer> s2;

        public CQueue() {
            s1 = new LinkedList<>();
            s2 = new LinkedList<>();
        }

        public void appendTail(int value) {
            s1.push(value);
        }

        public int deleteHead() {
            if (!s2.isEmpty()) return s2.pop();
            else {
                while(!s1.isEmpty())
                    s2.push(s1.pop());
                return s2.isEmpty() ? -1 : s2.pop();
            }
        }
    }
    class MinStack {
        Deque<Integer> s1;
        Deque<Integer> s2;

        /** initialize your data structure here. */
        public MinStack() {
            s1 = new LinkedList<>();
            s2 = new LinkedList<>();
        }

        public void push(int x) {
            s1.push(x);
            if (s2.isEmpty())
                s2.push(x);
            else
                s2.push(x > s2.peek() ? s2.peek() : x);
        }

        public void pop() {
            s1.pop();
            s2.pop();
        }

        public int top() {
            return s1.peek();
        }

        public int min() {
            return s2.peek();
        }
    }
}